#!/usr/bin/env python3
# -*- coding: utf-8 -*-
# @Time    : 2020/11/30 16:24
# @Author  : LuLu
# @FileName: tourguideTopicAndThemePage.py
# @Software: PyCharm

from time import sleep
from page import basePage
# from pagesLocators.navigationLocators import NavigationLoc
from pagesLocators.tourguideTopicAndThemeLocators import TopicAndThemeLoc as Loc
from pagesLocators.selectBoxLocators import SelectBoxLoc as selectLoc


class TourGuideTopicAndTheme(basePage.BasePage):
    """

    """

    # 输入关键词
    def sendKey_search_keyword(self, text):
        self.clear_and_sendKey_element(Loc.search_keyword, text)

    # 输入编号
    def sendKey_search_id(self, text):
        self.clear_and_sendKey_element(Loc.search_id, text)

    # 点击搜索
    def click_search(self):
        self.click_element(Loc.search_button)
        sleep(2)

    # 点击清空按钮
    def click_clean(self):
        self.click_element(Loc.clean_button)

    # 点击新增目的地按钮
    def click_add_button(self):
        self.click_element(Loc.addTopicAndTheme_button)

    # base已经封装单选多选方法

    # 点击顶部多选删除按钮
    def click_delete_button(self):
        try:
            self.click_element(Loc.select_delete_button)
            sleep(0.5)
            self.click_element(Loc.delete_yes)
            sleep(2)
        except:
            print('删除失败')

    # 点击单个删除
    def click_delete_one(self, num):
        try:
            self.click_element(Loc.delete_one(num))
            sleep(0.5)
            self.click_element(Loc.delete_yes)
        except:
            print('删除失败')

    # 点击单个编辑
    def click_edit_one(self, num):
        self.click_element(Loc.edit_one(num))

    # 删除成功提示语
    def get_toast_warn(self):
        return self.get_element_value(Loc.toast_warn) == '删除成功'

    # 获取某行是否勾选
    def get_rows_is_selected(self, row=1):
        return self.get_element_attribute(Loc.one_rows(row), 'class') == 'selected'

    # 获取表格rows行内容
    def get_table_rows(self, start_row=1, end_row=None):
        return self.get_table_row(Loc.list_table, start_row, end_row)

    # 获取表格lines列内容
    def get_table_lines(self, start_line=1, line_num=None):
        return self.get_table_line(Loc.list_table, start_line, line_num)

    """新增编辑框内容操作"""

    # 窗口title
    def get_Window_title(self):
        return self.get_element_value(Loc.win_title)

    # 主标题
    def sendKey_main_title(self, value, main_type='主题'):
        if main_type == '主题':
            self.clear_and_sendKey_element(Loc.subject_main_title, value)
        elif main_type == '话题':
            self.clear_and_sendKey_element(Loc.topic_main_title, value)

    # 获取主标题内容
    def get_main_title_value(self, main_type='主题', is_edit=None):
        if is_edit is None:
            if main_type == '主题':
                # text 输入方式的，get_value获取不到
                return self.get_element_attribute(Loc.subject_main_title, 'value')
            if main_type == '话题':
                # text 输入方式的，get_value获取不到
                return self.get_element_attribute(Loc.topic_main_title, 'value')
        elif is_edit == 'edit':
            # text 输入方式的，get_value获取不到
            return self.get_element_value(Loc.edit_main_title)

    # 副标题
    def sendKey_sub_title(self, value, main_type='主题'):
        if main_type == '主题':
            self.clear_and_sendKey_element(Loc.subject_sub_title, value)
        elif main_type == '话题':
            self.clear_and_sendKey_element(Loc.topic_sub_title, value)

    # 获取副标题内容
    def get_sub_title_value(self, sub_type='主题'):
        if sub_type == '主题':
            # text 输入方式的，get_value获取不到
            return self.get_element_attribute(Loc.subject_sub_title, 'value')
        if sub_type == '话题':
            # text 输入方式的，get_value获取不到
            return self.get_element_attribute(Loc.topic_sub_title, 'value')

    # 获取搜索id
    def get_edit_id(self):
        return self.get_element_value(Loc.edit_id)

    # main长度限制
    def get_main_length_limits(self):
        return self.get_element_value(Loc.main_length)

    # sub长度限制
    def get_sub_length_limits(self):
        return self.get_element_value(Loc.sub_length)

    # 填写排序
    def sendKey_sorted(self, value):
        self.clear_and_sendKey_element(Loc.sorted, value)

    # 获取排序
    def get_sorted(self):
        return self.get_element_attribute(Loc.sorted, 'value')

    # 移动问号
    def move_question_mark(self):
        self.move_to_element(Loc.question_mark)

    # 问号提示内容
    def get_question_mark_content(self):
        return self.get_element_value(Loc.question_tips)

    # 点击提交按钮
    def click_commit_button(self):
        sleep(1)
        self.click_element(Loc.commit_button)
        # self.driver.execute_script('arguments[0].click()', Loc.commit_button)

    # 点击取消按钮
    def click_cancel_button(self):
        self.click_element(Loc.cancel_button)

    # 点击关闭弹层
    def click_close_laye(self):
        self.click_element(Loc.close_button)
        sleep(1)

    # logo 是否上传成功
    def is_upload_success(self, pic_type):
        return self.isElementExist(Loc.logo_upload_success(pic_type))

    # 删除logo
    def delete_logo(self):
        self.click_element(Loc.delete_Logo_button)

    # 获取上传大小提示
    def get_upload_warn(self):
        return self.get_element_value(Loc.upload_warn)

    # 获取名字提示框
    def get_main_warn(self):
        return self.get_element_value(Loc.main_name_warn)

    # 获取排序提示框
    def get_sub_warn(self):
        return self.get_element_value(Loc.sub_name_warn)

    # 获取POI提示框
    def get_sorted_warn(self):
        return self.get_element_value(Loc.sorted_warn)

    # 获取LOGO提示框
    def get_LOGO_warn(self):
        return self.get_element_value(Loc.LOGO_warn)

    # 获取toast提示内容
    def get_toast_warn(self):
        return self.get_element_value(Loc.toast_warn) == '删除成功'

    def add_topic(self, add_parameter):
        """
        用于创建一个标准话题，如果话题已存在则return，不再继续创建
        :rtype: object
        """
        self.click_add_button()
        self.sendKey_main_title(add_parameter[0], '话题')
        self.sendKey_sub_title(add_parameter[1], '话题')
        if self.isElementExist(Loc.main_name_warn):
            if self.get_main_warn() == '话题已存在，请重新填写':
                self.click_close_laye()
                return
        self.sendKey_sorted(add_parameter[2])
        self.uploading_picture(Loc.select_Logo_button, add_parameter[3])
        self.click_commit_button()
        sleep(1)
